package com.casic.ops.controller.pipeline;

import com.casic.ops.entity.request.pipeline.PipelinePageRequest;
import com.casic.ops.entity.request.pipeline.PipelineRequest;
import com.casic.ops.entity.vo.pipeline.response.Response;
import com.casic.ops.service.api.pipeline.PipelineService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 流水线controller
 * @author cww
 * @date 2021-12-28 22:57:10
 */
@RestController
@Api(tags = "流水线模块",description = "包含新增/列表/删除")
@RequestMapping("ops/api/app/pipeline")
public class PipelineController  {

    @Resource
    private PipelineService pipelineService;

//    @GetMapping("/webhook/{uuid}")
//    @ApiOperation(value = "详情",httpMethod = "GET")
//    public Response webhook(@PathVariable String uuid){
//        return pipelineService.webhook(new PipelineWebhookExecuteCmd().setUuid(uuid));
//    }

    @PostMapping("/add")
    @ApiOperation(value = "添加",httpMethod = "POST")
    public Response add(@RequestBody PipelineRequest pipelineRequest) {
        return pipelineService.add(pipelineRequest);
    }

    @PostMapping("/deploy")
    @ApiOperation(value = "部署",httpMethod = "GET")
    public Response deploy(@RequestBody Long id) {
        return pipelineService.deploy(id);
    }

    @GetMapping("/execute")
    @ApiOperation(value = "运行",httpMethod = "Get")
    public Response execute(@RequestParam("id") Long id) {
//        PipelineTargetEnum hand = PipelineTargetEnum.HAND;
//        pipelineExecuteCmd.setTargetWay(hand).setTargetUser(UserThreadContext.get());

        return pipelineService.execute(id);
    }

    @GetMapping("/delete")
    @ApiOperation(value = "删除",httpMethod = "DELETE")
    public Response delete(@RequestParam("id") Long id){
        return pipelineService.delete(id);
    }

    @PostMapping("/batch/delete")
    @ApiOperation(value = "删除",httpMethod = "POST")
    public Response batchDelete(@RequestBody Long[] ids){
        return pipelineService.batchDelete(ids);
    }

    @PostMapping("/page")
    @ApiOperation(value = "列表",httpMethod = "GET")
    public Response page(@RequestBody PipelinePageRequest pipelinePageRequest){
        return pipelineService.page(pipelinePageRequest);
    }

    @GetMapping("/list")
    @ApiOperation(value = "列表",httpMethod = "GET")
    public Response list(){
        return pipelineService.list();
    }

    @GetMapping("/info")
    @ApiOperation(value = "详情",httpMethod = "GET")
    public Response info(@RequestParam("id") Long id){
        return pipelineService.getById(id);
    }

    @PutMapping("/update")
    @ApiOperation(value = "更新",httpMethod = "PUT")
    public Response update(@RequestBody PipelineRequest pipelineRequest){
        return pipelineService.update(pipelineRequest);
    }
}
